<?php
require_once('tags.php');
require_once('../auth.php');

if (!isUserLoggedIn()) {
	header("Location: index.php");
	exit();
}

$tags = new Tags();

$allTags = $tags->getAllTags();

$result = "[";
foreach ($allTags as $tag) {
	if (isset($tag["parametar"])) {
		$result = $result . '{ "id": "' . $tag["id"] . '", "label": "' . $tag["name"] . ' = ' . $tag["parametar"] . '", "value": "' . $tag["name"] . ' = ' . $tag["parametar"] . '" }';
	}
	else {
		$result = $result . '{ "id": "' . $tag["id"] . '", "label": "' . $tag["name"] . '", "value": "' . $tag["name"] . '" }';
	}
	
	$lastItem = end($allTags);
	if ($lastItem["id"] != $tag["id"]) {
		$result = $result . ", ";
	}
}
$result = $result . "]";
echo $result;
?>